<?php

/**
 * Wave Framework <http://www.waveframework.com>
 * View Controller
 *
 * Wave Framework comes with a View Controller and a translations system that is used to build 
 * a website on Wave Framework. This View Controller is entirely optional and can be removed 
 * from a system if you plan to implement your own View Controller or simply use Wave Framework 
 * for API, without a website.
 *
 * @package    Tools
 * @author     Kristo Vaher <kristo@waher.net>
 * @copyright  Copyright (c) 2012, Kristo Vaher
 * @license    GNU Lesser General Public License Version 3
 * @tutorial   /doc/pages/guide_view.htm
 * @since      1.0.0
 * @version    3.6.9
 */

class WWW_controller_articles extends WWW_Factory {

	/**
	 * This method is called by Data Handler to render View contents based on values from 
	 * URL Controller.
	 *
	 * @param array $input input data sent to controller
	 * @input mixed input data from URL Controller output
	 * @return null
	 */
	
	public function create_type($data)
	{
		//echo "<pre>";print_r($data);exit;
		$reason=array();
		if($data['title']=='')
		{
			$reason['titleerror']="Title should contain some value";
			$status="fail";
		}
		if($data['description']!='' && strlen($data['description'])>250)
		{
			$reason['descerror']="Description should be less than 250 characters only";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->create_article_type($data);
		return $this->resultTrue('result',$result);	
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function update_type($data)
	{
		if($data['article_type_id']=='')
		{
			$reason['iderror']="article_type_id should contain some value";
			$status="fail";
		}
		if($data['title']=='')
		{
			$reason['titleerror']="Title should contain some value";
			$status="fail";
		}
		if($data['description']!='' && strlen($data['description'])>250)
		{
			$reason['descerror']="Description should be less than 250 characters only";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->update_article_type($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function update_type_status($data)
	{
		if($data['article_type_id']=='')
		{
			$reason['iderror']="article_type_id should contain some value";
			$status="fail";
		}
		if($data['status']=='')
		{
			$reason['statuserror']="Status should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->update_article_type_status($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function get_article_type($data)
	{
		if($data['article_type_id']=='')
		{
			$reason['iderror']="article_type_id should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->get_article_type($data);
		return $this->resultTrue('result',$result);
		}else{
			return $this->resultTrue('result',$reason);
		}
	}
	public function all_types($data)
	{
		$model=$this->getModel('articles');
		$result=$model->get_all_types($data);
		return $this->resultTrue('result',$result);
		
	}
	public function create_author($data)
	{
		if($data['author_title']=='')
		{
			$reason['titleerror']="author_title should contain some value";
			$status="fail";
		}
		if($data['first_name']=='')
		{
			$reason['firstname_error']="first_name should contain some value";
			$status="fail";
		}
		if($data['middle_name']=='')
		{
			$reason['middlename_error']="middle_name should contain some value";
			$status="fail";
		}
		if($data['last_name']=='')
		{
			$reason['lastname_error']="last_name should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->create_article_author($data);
		return $this->resultTrue('result',$result);
		}else{
			return $this->resultTrue('result',$reason);
		}
	}
	public function update_author($data)
	{
		if($data['title']=='')
		{
			$reason['titleerror']="author_title should contain some value";
			$status="fail";
		}
		if($data['author_id']=='')
		{
			$reason['authorid_error']="authorid_error should contain some value";
			$status="fail";
		}
		if($data['first_name']=='')
		{
			$reason['firstname_error']="first_name should contain some value";
			$status="fail";
		}
		if($data['middle_name']=='')
		{
			$reason['middlename_error']="middle_name should contain some value";
			$status="fail";
		}
		if($data['last_name']=='')
		{
			$reason['lastname_error']="last_name should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->update_article_author($data);
		return $this->resultTrue('result',$result);
		}
		else{
			return $this->resultTrue('result',$reason);
		}
	}
	public function delete_author($data)
	{
		if($data['author_id']=='')
		{
			$reason['authorid_error']="author_id should contain some value";
			$status="fail";
		}
		if($data['status']=='')
		{
			$reason['statuserror']="Status should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->delete_author($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function get_authors($data)
	{
		$model=$this->getModel('articles');
		$result=$model->get_all_authors($data);
		return $this->resultTrue('result',$result);
	}
	public function create_disclaimer($data)
	{
		if($data['disclaimer_name']=='')
		{
			$reason['disclaimer_name_error']="disclaimer_name should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->create_article_disclaimer($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function update_disclaimer($data)
	{
		if($data['disclaimer_id']=='')
		{
			$reason['disclaimer_id_error']="disclaimer_id should contain some value";
			$status="fail";
		}
		if($data['disclaimer_name']=='')
		{
			$reason['disclaimer_name_error']="disclaimer_name should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->update_disclaimer($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function delete_disclaimer($data)
	{
		if($data['disclaimer_id']=='')
		{
			$reason['disclaimer_id_error']="disclaimer_id should contain some value";
			$status="fail";
		}
		if($data['status']=='')
		{
			$reason['statuserror']="Status should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->delete_disclaimer($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function get_disclaimers($data)
	{
		$model=$this->getModel('articles');
		$result=$model->get_disclaimers($data);
		return $this->resultTrue('result',$result);
	}
	public function get_disclaimers_list($data)
	{
		$model=$this->getModel('articles');
		$result=$model->get_disclaimers_list($data);
		return $this->resultTrue('result',$result);
	}
	public function get_articletype_list($data)
	{
		$model=$this->getModel('articles');
		$result=$model->get_articletype_list($data);
		return $this->resultTrue('result',$result);
	}
	public function get_authors_list($data)
	{
		$model=$this->getModel('articles');
		$result=$model->get_authors_list($data);
		return $this->resultTrue('result',$result);
	}
	public function create_article($data)
	{
		if($data['article_title']=='')
		{
			$reason['article_title_error']="article_title should contain some value";
			$status="fail";
		}
		if($data['article_type_id']=='')
		{
			$reason['article_type_id']="article_type_id should contain some value";
			$status="fail";
		}
		if($data['article_author_id']=='')
		{
			$reason['author_error']="Author should contain some value";
			$status="fail";
		}
		if($data['article_disclaimer_id']=='')
		{
			$reason['disclaimer_error']="Disclaimer should contain some value";
			$status="fail";
		}
		if($data['publish_date']=='')
		{
			$reason['publish_date_error']="publish_date should contain some value";
			$status="fail";
		}
		if($data['expiry_date']=='')
		{
			$reason['expiry_date_error']="expiry_date_error should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->create_article($data);
		return $this->resultTrue('result',$result);
		}else{
		return $this->resultTrue('result',$reason);
		}
	}
	public function update_article($data)
	{
		if($data['article_title']=='')
		{
			$reason['article_title_error']="article_title should contain some value";
			$status="fail";
		}
		if($data['article_id']=='')
		{
			$reason['article_id_error']="article_id should contain some value";
			$status="fail";
		}
		if($data['article_type_id']=='')
		{
			$reason['article_type_id']="article_type_id should contain some value";
			$status="fail";
		}
		if($data['article_author_id']=='')
		{
			$reason['author_error']="Author should contain some value";
			$status="fail";
		}
		if($data['article_disclaimer_id']=='')
		{
			$reason['disclaimer_error']="Disclaimer should contain some value";
			$status="fail";
		}
		if($data['publish_date']=='')
		{
			$reason['publish_date_error']="publish_date should contain some value";
			$status="fail";
		}
		if($data['expiry_date']=='')
		{
			$reason['expiry_date_error']="expiry_date_error should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->update_article($data);
		return $this->resultTrue('result',$result);
		}else{
		return $this->resultTrue('result',$reason);
		}
	}
	public function delete_article($data)
	{
		if($data['article_id']=='')
		{
			$reason['article_id_error']="article_id should contain some value";
			$status="fail";
		}
		if($data['status']=='')
		{
			$reason['statuserror']="Status should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->delete_article($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function get_articles($data)
	{
		$model=$this->getModel('articles');
		$result=$model->get_articles($data);
		return $this->resultTrue('result',$result);
	}
	public function get_article($data)
	{
		if($data['article_id']=='')
		{
			$reason['article_id_error']="article_id should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->get_article($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function get_disclaimer($data)
	{
		if($data['disclaimer_id']=='')
		{
			$reason['disclaimer_id_error']="disclaimer_id should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->get_disclaimer($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	public function get_author($data)
	{
		if($data['author_id']=='')
		{
			$reason['author_id_error']="author_id should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('articles');
		$result=$model->get_author($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	
}

?>